package com.xiaoming;

import com.xiaoming.filter.Calculator;
import com.xiaoming.service.ConsumerService;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;


public class ConsumerBootstrap {

    public static void main(String[] args) throws IOException, InterruptedException {

        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        ConsumerService service = context.getBean(ConsumerService.class);

        Timer timer = new Timer();
        Calculator calculator = new Calculator();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                calculator.calculate(System.currentTimeMillis());
                calculator.outPutTop();
            }
        }, 0, 5 * 1000);

        while (true) {
            for (int i = 0; i < 2000; i++) {
                new Thread(() -> service.doAction()).run();
            }
        }
    }

    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    //@EnableDubbo(scanBasePackages = "com.lagou.bean")
    @ComponentScan("com.xiaoming.service")
    @EnableDubbo
    static class ConsumerConfiguration {

    }
}
